<?php
/**
 * ------获取商家权限状态
 * Created by PhpStorm.
 * User: itboot
 * Date: 18-9-27
 * Time: 上午11:29
 */

namespace Biz\service;

use Biz\model\DefaultAuthority as authorityModel;
use Biz\model\ShopAuthority as shopAuthorityModel;
/**
 * @deprecated
 */
class ShopAuthority
{
    const AUTHORITY_STATUS_TRUE = 1; //权限状态（１为开放，０为关闭）
    const DEFAULT_SHOPAUTHORITY = 2; //权限状态（2为默认）

    /**
     * ---------获取商家权限信息
     * @param $shop_id
     * @return array|mixed　['权限标识'　=> true, '权限标识'　=> false]
     */
    public static function getAuthorityList($shop_id)
    {
        $defaultAuthorityList = authorityModel::getShopAuthorityList();
        $shopAuthority = shopAuthorityModel::getAuthorityRow($shop_id ,'authority_status');
        if (empty($shopAuthority)) {
            foreach($defaultAuthorityList as $value) {
                $defaultAuthority[$value['authority_key']] = $value['authority_status'] == self::AUTHORITY_STATUS_TRUE ? true : false;
            }
            return $defaultAuthority;
        } else {
            $shopAuthorityList = json_decode($shopAuthority, true);
            foreach ($defaultAuthorityList as $value) {
                if (isset($shopAuthorityList[$value['authority_key']])) {
                    if ($shopAuthorityList[$value['authority_key']] == self::DEFAULT_SHOPAUTHORITY) {
                        $defaultAuthority[$value['authority_key']] = $value['authority_status'] == self::AUTHORITY_STATUS_TRUE ? true : false;
                    } else {
                        $defaultAuthority[$value['authority_key']] = $shopAuthorityList[$value['authority_key']] == self::AUTHORITY_STATUS_TRUE ? true : false;
                    }
                } else {
                    $defaultAuthority[$value['authority_key']] = $value['authority_status'] == self::AUTHORITY_STATUS_TRUE ? true : false;
                }
            }

            return $defaultAuthority;
        }
    }
}
